home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-01.zip / 01 / Hity z okladki / OrgPlus 6 SBE / ORGPL.CAB / toolbarFunc.js < prev    next >
Text File  |  2006-09-20  |  12KB  |  481 lines

  1. /**********************************************************
  2. *                                                         *
  3. * (C) Copyright 2002 - 2004,  Human Concepts (tm)         *
  4. *                                                         *
  5. ***********************************************************
  6. * File name: toolbarFunc.js                               *
  7. * Author: Andrey Ponomarev                                *
  8. **********************************************************/
  9.  
  10.   var zoomValue = 1.0;    
  11.   var bZoomOnWheel = false
  12.   var oOverwiewWnd
  13.   var bZoomInitReady = false
  14.   var bFitToWindow = false    
  15.  
  16.   var nZoomFitButtonNumber = 3
  17.   var nZoomWheelButtonNumber = 4
  18.  
  19.   window.onunload = doUnload
  20.  
  21.   var strZoomSupportMsg = "To fully support OrgPlus HTML Zoom functionality,\n\ryou will need to upgrade your Internet Explorer to\n\rat least version 5.5" //Loc
  22.  
  23.   function doUnload()
  24.   {
  25.     if ( typeof(oOverwiewWnd) == "object" && !oOverwiewWnd.closed)
  26.     {
  27.       oOverwiewWnd.close()
  28.     }
  29.   }
  30.  
  31.   function buttonIn_onclick() 
  32.   {
  33.     ClearAutoFitFlag()
  34.     DoZoomIn()
  35.   }
  36.  
  37.   function ClearAutoFitFlag()
  38.   {
  39.     if (getIEVersion() >= 5.5 && typeof(oToolBar) != 'undefined')
  40.       oToolBar.getItem(nZoomFitButtonNumber).setAttribute('selected', 'false')
  41.   }
  42.  
  43.   function SetAutoFitFlag()
  44.   {
  45.     if (getIEVersion() >= 5.5 && typeof(oToolBar) != 'undefined')
  46.       oToolBar.getItem(nZoomFitButtonNumber).setAttribute('selected', 'true')
  47.   }
  48.  
  49.   function buttonOut_onclick() 
  50.   {
  51.     ClearAutoFitFlag()
  52.     DoZoomOut()
  53.   }
  54.  
  55.   function setZoomExt(zoomVal) 
  56.   {
  57.     var ver = getIEVersion()
  58.     if (ver < 5.5)
  59.       alert(strZoomSupportMsg)
  60.     else if (zoomVal > 0)
  61.     { 
  62.       switchScrolling(true);
  63.       setZoom(zoomVal)
  64.     }
  65.     else
  66.       ZoomToFit()      
  67.   }
  68.  
  69.   function buttonZoomToFit_onclick()
  70.   { 
  71.     if (getIEVersion() < 5.5)
  72.     {
  73.       alert(strZoomSupportMsg)
  74.     }
  75.     else
  76.     {
  77.       top.bAutoFitToWindow = !top.bAutoFitToWindow
  78.       if (top.bAutoFitToWindow && !bFitToWindow)
  79.         ZoomToFit()
  80.     }
  81.   }
  82.  
  83.   function ZoomToFitInit()
  84.   {
  85.     if (getIEVersion() < 5.5)
  86.     {
  87.       tryCenterPage()
  88.       updateOverviewWindow()
  89.     }
  90.     else
  91.     {
  92.       if (!bZoomInitReady)
  93.       {
  94.         DoZoomToFitInit()
  95.         bZoomInitReady = true        
  96.       }
  97.       else
  98.       {
  99.         ClearAutoFitFlag()
  100.         setZoom(zoomValue)
  101.       }        
  102.     }
  103.   }
  104.   
  105.   function HitTestReaction()
  106.   {
  107.     //alert('hit test')//onClickGroup()
  108.   }
  109.     
  110.   function UpdateHitTestRectsByZoom()
  111.   {
  112.     if (!isSelectionEnabled())
  113.       return
  114.  
  115.     var st_strRectForHitTestName = "_HitTestRect" 
  116.     var groupObjs = top.hcMain.PageGroup.document.getElementsByTagName("group")
  117.     var zoomValue = parseFloat(top.hcMain.PageGroup.style.zoom)
  118.     if (zoomValue == 0.0)
  119.       zoomValue = 0.01
  120.     for (i = 0; i < groupObjs.length; i++)
  121.     {
  122.       var objGroup = groupObjs[i]
  123.       if (objGroup.id == "PageGroup")
  124.         continue
  125.         
  126.           var strName = objGroup.id + st_strRectForHitTestName
  127.           var bFound = false
  128.       var elem
  129.           for (j = 0; j < objGroup.children.length; j++)
  130.           {
  131.               if (objGroup.children[j].id == strName)
  132.               {
  133.                 elem = objGroup.children[j]
  134.                 bFound = true
  135.                 break
  136.               }
  137.           }
  138.         
  139.           if (!bFound)//if not found - create
  140.       {
  141.         elem = objGroup.document.createElement("v:rect")
  142.         elem.id = strName
  143.         elem.style.top = 0
  144.         elem.style.left = 0
  145.         elem.setAttribute("stroked", "false") 
  146.         //elem.setAttribute("filled", "false") 
  147.         
  148.         //elem.onclick = HitTestReaction
  149.         
  150.         var fill = objGroup.document.createElement("v:fill")
  151.         fill.setAttribute("color", "#009000")          
  152.         fill.setAttribute("opacity", ".0")
  153.     
  154.         objGroup.appendChild(elem)
  155.         elem.appendChild(fill);
  156.       }
  157.       
  158.       if (typeof(elem) == "object")
  159.       {
  160.         var k = 1. / zoomValue;
  161.         var m = objGroup.style.pixelWidth
  162.         if (k > 1)
  163.           m = m * k
  164.         else 
  165.           m = 0
  166.         elem.style.width = m
  167.         
  168.         m = objGroup.style.pixelHeight
  169.         if (k > 1)
  170.           m = m * k
  171.         else 
  172.           m = 0
  173.         elem.style.height = m
  174.       }      
  175.     }
  176.   }
  177.     
  178.   function onZoomCombo()
  179.   {
  180.     ClearAutoFitFlag()
  181.     var obj = event.srcElement
  182.     setZoomExt(obj.value)
  183.     top.hcMain.focus()
  184.   }
  185.  
  186.   function buttonPrint_onclick()
  187.   {
  188.     var obj = top.hcMain
  189.     if (typeof(obj) == 'object' && typeof(obj.clearBoxHighlighting) != 'undefined')
  190.     {
  191.       obj.clearBoxHighlighting()
  192.       obj.focus()
  193.       obj.print()
  194.     }
  195.   }
  196.  
  197.   function buttonOverview_onclick()
  198.   {
  199.     if ( typeof(oOverwiewWnd) == "undefined" || 
  200.          typeof(oOverwiewWnd) == "object" && oOverwiewWnd.closed )
  201.     {
  202.       var objMain = top.hcMain
  203.       if ( typeof(objMain) != "object" || typeof(objMain.PageGroup) != "object" )
  204.       {
  205.         //onOverviewClosed()
  206.         alert("Sorry, can't display Overview Window - Chart document is not loaded yet") //Loc
  207.         return         
  208.       }
  209.  
  210.       oOverwiewWnd = window.showModelessDialog("overviewWnd.html", window, 
  211.          "dialogHide=yes; center=no; help=no; dialogLeft=500; dialogTop=30; status=no; dialogHeight:10; dialogWidth:14; resizable:no; scroll:no; edge:sunken");
  212.     }
  213.     else
  214.     {
  215.       oOverwiewWnd.close()
  216.     }
  217.   }
  218.  
  219.   function onOverviewWndCreated() 
  220.   {
  221.     initOverviewWindow()
  222.     updateOverviewWindow()
  223.   }
  224.  
  225.   function updateOverviewWindow()
  226.   {
  227.     if ( typeof(oOverwiewWnd) == "object" && !oOverwiewWnd.closed)
  228.     {
  229.       oOverwiewWnd.draw(top.hcMain)
  230.     }
  231.   }
  232.  
  233.   function initOverviewWindow()
  234.   {
  235.     if ( typeof(oOverwiewWnd) == "object" && !oOverwiewWnd.closed)
  236.     {
  237.       var objMain = top.hcMain
  238.       if (typeof(objMain) == "object")
  239.       {
  240.         var objPageGroup = objMain.document.getElementById("PageGroup")
  241.         if (typeof(objPageGroup) == "object")
  242.         {
  243.           var strImg = objMain.strImageForPreview
  244.           if ( typeof(strImg) == 'undefined' )
  245.             strImg = ""
  246.           oOverwiewWnd.initPage( objPageGroup, strImg )
  247.         }
  248.       }
  249.     }
  250.   }
  251.  
  252.   function buttonShowHidePanels_onclick()
  253.   {
  254.     if (top.isShowPanelsEnable())
  255.     {
  256.       top.bHidePanelsByDefault = !top.bHidePanelsByDefault;
  257.       top.DoHideShowPanels();
  258.     }
  259.   }
  260.  
  261.   function buttonZoomOnWheel_onclick()
  262.   {
  263.     bZoomOnWheel = !bZoomOnWheel
  264.     var ver = getIEVersion()
  265.     if (bZoomOnWheel && ver < 6.0)
  266.     {
  267.       if ( typeof(oToolBar) != 'undefined' )
  268.         oToolBar.getItem(nZoomWheelButtonNumber).setAttribute('selected', 'true')
  269.       alert("You should Update Internet Explorer to Version 6.0 or higher\r\nto have Zoom on Mouse Wheel") //Loc 
  270.     }
  271.   }
  272.  
  273.   function onChartMouseWheeling(evnt)
  274.   {
  275.     if (bZoomOnWheel)
  276.     {
  277.       if (evnt.wheelDelta >= 120)
  278.       {
  279.         buttonIn_onclick()
  280.       }
  281.       else if (evnt.wheelDelta <= -120)
  282.       {
  283.         buttonOut_onclick()
  284.       }
  285.     }
  286.   }
  287.  
  288.   function HumanConcepts_onclick() 
  289.   {
  290.     top.location = "http://www.humanconcepts.com"
  291.   }
  292.  
  293.   function isSelectionEnabled()
  294.   {
  295.     return (top.bIndexPage || top.bCountPage || top.bProfilePage)
  296.   }
  297.  
  298.   function tryCenterPage()
  299.   {
  300.     var obj = top.hcMain.document.body 
  301.     var wndHeight = parseInt(obj.clientHeight) 
  302.     var wndWidth = parseInt(obj.clientWidth)
  303.  
  304.     var oPage = top.hcMain.PageGroup
  305.     if (typeof(oPage) != "object")
  306.       return
  307.  
  308.     oPage.style.visibility = 'hidden'
  309.  
  310.     var nZoomValue = 1.
  311.     if (getIEVersion() >= 5.5)
  312.       nZoomValue = zoomValue
  313.  
  314.     var pageHeight = oPage.style.pixelHeight * nZoomValue
  315.     var pageWidth = oPage.style.pixelWidth * nZoomValue
  316.  
  317.     var nLeft = 0
  318.     if (wndWidth > pageWidth)
  319.       nLeft = (wndWidth - pageWidth) / 2
  320.  
  321.     var nTop = 0
  322.     if (wndHeight > pageHeight)
  323.       nTop = (wndHeight - pageHeight) / 2
  324.  
  325.     oPage.style.left = parseInt(nLeft)
  326.     oPage.style.top = parseInt(nTop)
  327.  
  328.     oPage.style.visibility = 'visible'
  329.  
  330.   } 
  331.  
  332.   function DoZoomIn()
  333.   {
  334.     if (zoomValue < 3)
  335.     {
  336.       if (zoomValue < 0.1)  
  337.         zoomValue = 0.1
  338.       else if (zoomValue < 0.2)  
  339.         zoomValue = 0.2
  340.       else if (zoomValue < 0.4)  
  341.         zoomValue = 0.4        
  342.       else if (zoomValue < 0.6)  
  343.         zoomValue = 0.6        
  344.       else if (zoomValue < 0.8)  
  345.         zoomValue = 0.8
  346.       else if (zoomValue < 1.0)  
  347.         zoomValue = 1.0
  348.       else if (zoomValue < 1.5)  
  349.         zoomValue = 1.5        
  350.       else if (zoomValue < 2.0)  
  351.         zoomValue = 2.0        
  352.       else if (zoomValue < 2.5)  
  353.         zoomValue = 2.5        
  354.       else if (zoomValue < 3.0)  
  355.         zoomValue = 3.0
  356.         
  357.       setZoomExt(zoomValue)
  358.     }
  359.   }
  360.  
  361.   function DoZoomOut()
  362.   {
  363.     if (zoomValue > 0.1)
  364.     {
  365.       if (zoomValue > 3.0)  
  366.         zoomValue = 3.0
  367.       else if (zoomValue > 2.5)  
  368.         zoomValue = 2.5
  369.       else if (zoomValue > 2.0)  
  370.         zoomValue = 2.0
  371.       else if (zoomValue > 1.5)  
  372.         zoomValue = 1.5
  373.       else if (zoomValue > 1.0)  
  374.         zoomValue = 1.0
  375.       else if (zoomValue > 0.8)  
  376.         zoomValue = 0.8
  377.       else if (zoomValue > 0.6)  
  378.         zoomValue = 0.6
  379.       else if (zoomValue > 0.4)  
  380.         zoomValue = 0.4
  381.       else if (zoomValue > 0.2)  
  382.         zoomValue = 0.2
  383.       else if (zoomValue > 0.1)  
  384.         zoomValue = 0.1
  385.  
  386.       setZoomExt(zoomValue)
  387.     }
  388.   }
  389.  
  390.   function setZoom(value)
  391.   {
  392.     zoomValue = parseFloat(value)
  393.     //var tmpInt = parseInt( (parseFloat(value) + 0.01) * 10) //to avoid bug with float value
  394.     //zoomValue = tmpInt / 10
  395.     if (zoomValue < 0.0)
  396.     {
  397.       zoomValue = Math.abs(zoomValue)
  398.       bFitToWindow = true;  
  399.     }
  400.     else 
  401.     {
  402.       bFitToWindow = false;
  403.       if (zoomValue < 0.1)
  404.         zoomValue = 0.1
  405.     }
  406.  
  407.     if ( typeof(oToolBar) != 'undefined' && typeof(oToolBar) == 'object' )
  408.     {
  409.       var item2 = oToolBar.getItem(2)
  410.       if (typeof(item2) == 'object' && typeof(item2.setAttribute) != 'undefined')
  411.       {
  412.         if (bFitToWindow == false)
  413.           item2.setAttribute('value', zoomValue)
  414.         else
  415.           item2.setAttribute('value', 0)        
  416.       }
  417.     }
  418.  
  419.     var obj = top.hcMain.PageGroup
  420.     if (typeof(obj) == "object")
  421.     {
  422.       obj.style.visibility = 'hidden'
  423.       obj.style.zoom = zoomValue
  424.       obj.style.visibility = 'visible'
  425.     }
  426.  
  427.     tryCenterPage()
  428.     
  429.     UpdateHitTestRectsByZoom()
  430.  
  431.     updateOverviewWindow()
  432.   }
  433.  
  434.   function switchScrolling(b)
  435.   {  
  436.     var obj = top.hcMain.document.body
  437.     if(b)
  438.       obj.setAttribute("scroll","auto"); 
  439.     else
  440.       obj.setAttribute("scroll","no"); 
  441.   }
  442.       
  443.   function ZoomToFit()
  444.   {
  445.     var obj = top.hcMain.document.body //top.hcMain.frameElement
  446.     var wndHeight = parseInt(obj.clientHeight) 
  447.     var wndWidth = parseInt(obj.clientWidth)
  448.  
  449.     var oPage = top.hcMain.PageGroup
  450.     if (typeof(oPage) != "object")
  451.       return
  452.     
  453.     switchScrolling(false)
  454.     oPage.style.visibility = 'hidden';
  455.  
  456.     var pageHeight = oPage.style.pixelHeight + 20
  457.     var pageWidth = oPage.style.pixelWidth + 20      
  458.  
  459.     var d = wndHeight / pageHeight
  460.     if (pageWidth * d > wndWidth )
  461.     d = wndWidth / pageWidth
  462.  
  463.     if (getIEVersion() < 5.5)
  464.     {
  465.       tryCenterPage()
  466.       updateOverviewWindow()
  467.     }
  468.     else
  469.     {   
  470.       setZoom(-d)
  471.     }
  472.  
  473.     oPage.style.visibility = 'visible';    
  474.   }
  475.  
  476.   function DoZoomToFitInit()
  477.   {
  478.     ZoomToFit()
  479.   }
  480.  
  481.